using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.WorkItemTracking;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.Controls;
using C1.Win.C1FlexGrid;

namespace Hemi
{
    public class HemiMovePipeline
    {
        List<IMoveStage> _pipeLine;
        int _pipeLineIndex = 0;

        public HemiMovePipeline()
        {
            _pipeLine = new List<IMoveStage>();

            _pipeLine.Add(new QueryForWorkItems());            
            _pipeLine.Add(new MapTypesStage());
            _pipeLine.Add(new CommitMoveStage());            
            _pipeLine.Add(new NewWorkItemsStage());
        }

        public IMoveStage CurrentStage
        {
            get
            {
                return _pipeLine[_pipeLineIndex];
            }
        }

        public bool PeekHasMore()
        {
            int nextIndex = _pipeLineIndex + 1;

            return (nextIndex < _pipeLine.Count);
        }

        /// <summary>        
        /// </summary>
        /// <returns>True if we have reached the last stage; false otherwise</returns>
        public void MoveNextStage()
        {           
            if (CurrentStage.CanTestValidate && !CurrentStage.Validate())
            {
                MessageBox.Show(CurrentStage.InvalidMessage);            
            }
            else
            {
                CurrentStage.CommitChanges();

                int nextIndex = _pipeLineIndex + 1;

                if (nextIndex < _pipeLine.Count)
                {
                    _pipeLineIndex = nextIndex;
                }
            }
        }       
    }
}
